/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportcenter.report.ui;

import javax.swing.JOptionPane;
import org.springframework.richclient.dialog.CloseAction;
import org.springframework.richclient.dialog.ConfirmationDialog;
import org.springframework.richclient.dialog.FormBackedDialogPage;
import org.springframework.richclient.dialog.TitledPageApplicationDialog;
import org.springframework.richclient.form.Form;
import reportcenter.report.dominio.export.Export;
import reportcenter.report.dominio.report.Report;

/**
 *
 * @author renan_luz
 */
public class ExportReportPropertiesDialog extends TitledPageApplicationDialog {

    private Form form;
    private Report report;

    public ExportReportPropertiesDialog(Report report) {
        this.report = report;
        setCloseAction(CloseAction.DISPOSE);
        form = new ExportReportForm(new Export());
        setDialogPage(new FormBackedDialogPage(form));
    }

    protected void onAboutToShow() {
        String title = getMessage("Parametrizando relatorio: ", new Object[]{report.getTitle()});
        setTitle(title);

    }

    protected boolean onFinish() {
        // commit any buffered edits to the model
//        form.getFormModel().commit();
        JOptionPane.showMessageDialog(null, "Gerar relatorio");

        return true;
    }

    protected void onCancel() {
        // Warn the user if they are about to discard their changes
        if (form.getFormModel().isDirty()) {
            String msg = getMessage("exportReportProperties.dirtyCancelMessage");
            String title = getMessage("exportReportProperties.dirtyCancelTitle");
            ConfirmationDialog dlg = new ConfirmationDialog(
                    title,
                    msg) {

                protected void onConfirm() {
                    ExportReportPropertiesDialog.super.onCancel();
                }
            };
            dlg.showDialog();
        } else {
            super.onCancel();
        }
    }
}
